{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# slice and concat tf tensors to realise replace column\n",
    "\n",
    "import tensorflow as tf\n",
    "\n",
    "t1 = [[1, 20, 3], \n",
    "      [4, 50, 6], \n",
    "      [7, 80, 9]]\n",
    "left = tf.slice(t1, [0, 0],[3, 1])\n",
    "right = tf.slice(t1, [0, 1+1],[3, -1])\n",
    "print(left)\n",
    "print(right)\n",
    "\n",
    "t2 = [[2],\n",
    "      [5], \n",
    "      [8]]\n",
    "combined = tf.concat([left, t2 ,right], 1)\n",
    "print(combined)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = build_area_seqs(target_area, start='2016-10-01', end='2016-11-01')\n",
    "# normalization\n",
    "data = data/data.max()\n",
    "time_len = data.shape[0]\n",
    "N = data.shape[1] # 11\n",
    "max_parks = data[nks[target_park]].max()\n",
    "data.plot(figsize=(20, 5), title='Raw Data')\n",
    "# add noise for target_park\n",
    "data[nks[target_park]] = np.random.normal(max_parks/2.0, max_parks/10.0, size=(time_len))\n",
    "data.plot(figsize=(20, 5), title='Noised Data')\n",
    "\n",
    "# area_df = build_area_seqs(target_area)\n",
    "# area_df.to_csv('data/area_seqs/'+target_park+'_area_seq.csv',encoding='utf_8_sig', index=False)   "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "import seaborn as sns\n",
    "from skimage.util import montage\n",
    "from IPython.display import Image, display, SVG, clear_output, HTML\n",
    "plt.rcParams[\"figure.figsize\"] = (6, 6)\n",
    "plt.rcParams[\"figure.dpi\"] = 125\n",
    "plt.rcParams[\"font.size\"] = 14\n",
    "plt.rcParams['font.family'] = ['sans-serif']\n",
    "plt.rcParams['font.sans-serif'] = ['DejaVu Sans']\n",
    "plt.style.use('ggplot')\n",
    "sns.set_style(\"whitegrid\", {'axes.grid': False})\n",
    "plt.rcParams['image.cmap'] = 'gray' # grayscale looks better\n",
    "\n",
    "def draw_graph_mpl(g, pos=None, ax=None, layout_func=nx.drawing.layout.kamada_kawai_layout, draw_labels=True):\n",
    "    if ax is None:\n",
    "        fig, ax = plt.subplots(1, 1, figsize=(20, 20))\n",
    "    else:\n",
    "        fig = None\n",
    "    if pos is None:\n",
    "        pos = layout_func(g)\n",
    "    node_color = []\n",
    "    node_labels = {}\n",
    "    shift_pos = {}\n",
    "    for k in g:\n",
    "        node_color.append(g.nodes[k].get('color', 'green'))\n",
    "        node_labels[k] = g.nodes[k].get('label', k)\n",
    "        shift_pos[k] = [pos[k][0], pos[k][1]]\n",
    "    \n",
    "    edge_color = []\n",
    "    edge_width = []\n",
    "    for e in g.edges():\n",
    "        edge_color.append(g.edges[e].get('color', 'black'))\n",
    "        edge_width.append(g.edges[e].get('width', 0.5))\n",
    "    nx.draw_networkx_edges(g, pos, font_weight='bold', edge_color=edge_color, width=edge_width, alpha=0.5, ax=ax)\n",
    "    nx.draw_networkx_nodes(g, pos, node_color=node_color, node_shape='p', node_size=300, alpha=0.75, ax=ax)\n",
    "    if draw_labels:\n",
    "        nx.draw_networkx_labels(g, shift_pos, labels=node_labels, arrows=True, ax=ax)\n",
    "    ax.autoscale()\n",
    "    return fig, ax, pos"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "\n",
    "def get_site_attr(site_name, attr):\n",
    "    basic_info_df = pd.read_csv('generated/data/parkings_info.csv')\n",
    "    return basic_info_df.loc[basic_info_df.parking_name == site_name].iloc[0][attr]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "124"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "get_site_attr('万山珠宝工业园','total_space')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
